import year2019.month08.TreeNode;

public class Test {

    public static void main(String[] args) {

        TreeNode root = new TreeNode("10");
        TreeNode treeNode1 = new TreeNode("12");
        TreeNode treeNode2 = new TreeNode("13");
        TreeNode treeNode3 = new TreeNode("18");
        TreeNode treeNode4 = new TreeNode("19");
        TreeNode treeNode5 = new TreeNode("23");
        TreeNode treeNode6 = new TreeNode("55");

        root.setLeftNode(treeNode1);
        root.setRightNode(treeNode2);

        treeNode1.setLeftNode(treeNode3);
        treeNode1.setRightNode(treeNode4);

        treeNode2.setLeftNode(treeNode5);

        treeNode4.setRightNode(treeNode6);

        //前序遍历
        preorderTraversal(root);
        System.out.println();

        //中序遍历
        inorderTraversal(root);
        System.out.println();

        //后序遍历
        postorderTraversal(root);
        System.out.println();

    }

    //前序遍历：根节点-->左子节点-->右子节点
    public static void preorderTraversal(TreeNode root){
        if (root!=null){
            System.out.print(root.getData()+"、");
            preorderTraversal(root.getLeftNode());
            preorderTraversal(root.getRightNode());
        }
    }

    //中序遍历：左子节点-->根节点-->右子节点
    public static void inorderTraversal(TreeNode root){
        if (root!=null){
            inorderTraversal(root.getLeftNode());
            System.out.print(root.getData()+"、");
            inorderTraversal(root.getRightNode());
        }
    }

    //后序遍历：左子节点-->右子节点-->根节点
    public static void postorderTraversal(TreeNode root){
        if (root!=null){
            postorderTraversal(root.getLeftNode());
            postorderTraversal(root.getRightNode());
            System.out.print(root.getData()+"、");
        }
    }

}
